﻿def first_interface():
    print('+--------------------+')
    print('| 1)添加学生信息     |')
    print('| 2)显示学生信息     |')
    print('| 3)修改学生信息     |')
    print('| 4)删除学生信息     |')
    print('| 5)退出程序         |')
    print('+--------------------+')
L = []
informations = []
def input_info(**kwargs):
    L.append(kwargs)
    global L
    return L
def input_student():
    print('请再添加几个学生信息．．．')
    global L
    while True:
        name=input("请输入姓名：")
        if not name:
            break
        age=int(input("请输入年龄："))
        score=int(input("请输入成绩"))
        input_info(name=name,age=age,score=score)
    return L
def output_student(L):
    print('+---------------+----------+----------+')
    print('|     name      |   age    |   score  |')  
    print('+---------------+----------+----------+')
    for d in L:
        center_name = d['name'].center(15)
        str_age = str(d['age'])
        center_age = str_age.center(10)
        center_score = str(d['score']).center(10)
        line = "|%s|%s|%s|"%(center_name,
            center_age,center_score)
        print(line)
    print('+---------------+----------+----------+')
def change(L):
    if L==[]:
        print("还没有任何信息,正在返回首页...")
    else:
        output_student(L)
        print("你要修改谁的信息？提醒：只能修改成绩信息！！！")
        x = input("请输入要修改时的学生姓名：")
        for d in L:
            if d["name"]==x:
                index_of=L.index(d)
                print(index_of)
                new_scor = int(input("请输入"+x+"的新的成绩:"))
                L[index_of]['score']=new_scor
                output_student(L)
            else:
                print("没有这样的信息，正在返回首页...")
    return L
def delete_info(L):
    if L==[]:
        print("还没有任何信息,正在返回首页...")
    else:
        output_student(L)
        print("你要删除谁的信息？提醒：删除后无法恢复信息！！！")
        x = input("请输入要删除的学生姓名：")
        for d in L:
            if d["name"]==x:
                index_of=L.index(d)
                del L[index_of]
                print(x+"的信息已删除，正在返回的首页...")
                output_student(L)
            else:
                print("没有这样的信息，输出结果后自动返回首页...")
    return L
while True:
    first_interface()
    n = int(input("请选择进行操作："))
    if n==1:
        input_student()
        continue
    elif n==2:
        if L==[]:
            print("还没有任何信息,正在返回首页...")
            continue
        else:
            output_student(L)
    elif n==3:
        change(L)
        continue
    elif n==4:
        delete_info(L)
        continue
    elif n==5:
        print("正在退出...")
        break